var graph = argument0;
var height = array_height_2d(graph);
var width = array_length_2d(graph, 0);

var start = 0;
var maxDistance = 0;
var maxLocation = 0;
//TODO: OPTIMIZE
for (var iii = 0; iii < height; iii++)
{
    for (var jjj = 0; jjj < width; jjj++)
    {
        if (graph[iii, jjj] == 1)
        {
            graph[@ iii, jjj] = 'A';
            start[0] = iii;
            start[1] = jjj;
        }
    }
}

for (var iii = 0; iii < height; iii++)
{
    for (var jjj = 0; jjj < width; jjj++)
    {
        //Make sure start and finish aren't too close
        if (is_real(graph[iii, jjj]) && graph[iii, jjj] > maxDistance && 
            abs(iii - start[0]) + abs(jjj - start[1]) > 10)
        {
            maxDistance = graph[iii, jjj];
            maxLocation[0] = iii;
            maxLocation[1] = jjj;
        }
    }
}

for (var iii = 0; iii < height; iii++)
{
    for (var jjj = 0; jjj < width; jjj++)
    {
        if (is_real(graph[iii, jjj]) && graph[iii, jjj] > maxDistance)
        {
            graph[@ iii, jjj] = 0;
        }
    }
}

graph[@ maxLocation[0], maxLocation[1]] = 'B';